﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PassportsModel;
using Neuron.Esb;

namespace IdentifyClient
{
    public partial class Form1 : Form
    {
        Publisher _Publisher;

        public Form1()
        {
            InitializeComponent();

            _Publisher = new Publisher("ClientIdentityPublisher");

            _Publisher.Connect();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SendMessage();
        }

        private void SendMessage()
        {
            PassportRequest identityRequest = new PassportRequest(eGender.Female, eGender.Female);           

            identityRequest.PersonDetails.BirthDate = DateTime.ParseExact("1950/12/31", "yyyy/MM/dd", System.Globalization.CultureInfo.CurrentCulture);

            //identityRequest.PersonDetails.Gender = eGender.Female;
            identityRequest.PersonDetails.FamilyName = "Wilberforce";
            identityRequest.PersonDetails.GivenNames = "Wilber";

            identityRequest.PassportType = ePassportType.Adult;
            identityRequest.PassportTravellerType = ePassportTravellerType.Ordinary;

            ESBMessage identityRequestMessage = new ESBMessage();

            identityRequestMessage.Header = new ESBMessageHeader();
            identityRequestMessage.Header.Semantic = Semantic.Request;
            identityRequestMessage.Header.Topic = "IdentityRequest";
           
            //identityRequestMessage.Header.SourceId = "Client1";

            
            //identityRequestMessage.Header.FaultType = FaultType.None;            
            identityRequestMessage.Body = identityRequest;
          
            _Publisher.SendMessage(identityRequestMessage);

            ESBMessage responseMessage = _Publisher.Send("IdentityRequest", identityRequest, SendOptions.Request);

            PassportResponse identityResponse = responseMessage.GetBody<PassportResponse>();
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SendMessage();
        }
    }
}
